<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        alert("这是一个猜字游戏，请选一个0-50之间的数\n注意你只有10次机会哟！！");
        let temp = 0;
        let num1 = parseInt(Math.random()*100/2);
        let num;
        while (temp<10) {
            num = +prompt("请输入你选的数字");
            console.log(num);
            if(num === num1)
            {
                alert("恭喜你猜对了");
                temp = 20;
                document.write("游戏结束");
            }else if(num > num1)
            {
                alert("你猜的数太大了");
                temp++;
            }else{ alert("你猜的太小了"); temp++;}
        }
        if(temp<20){
            document.write("很遗憾你没有猜对，答案是：",num1,"<br>刷新页面再来一次吧");
        }
    </script>
</body>
</html>